#ifndef  WWFRONTEND_CMD_IMRECEIVER_H
#define  WWFRONTEND_CMD_IMRECEIVER_H

#include "../Core/msgbus_interface.h"
#include "../Core/msgbus_handlerbase.hpp"
#include "../Biz/MsgBusParam/IMContactParam.h"
#include "../Biz/MsgBusParam/IMFileTransferParam.h"
#include <boost/noncopyable.hpp>
#include <string>
#include <map>
#include <set>

using namespace NetMsgBus;
using namespace wwbiz;

class IMReceiver: public MsgHandler<IMReceiver>, public boost::noncopyable
{
public:
    IMReceiver();
    ~IMReceiver();
    void InitMsgHandler();
    void NotifyQuitToWWMain();
    void NotifyReadyToWWMain();
    void SetWWMainUniqueFlag(const std::string& unique);
    bool OnReqQuit(const std::string& msgid, MsgBusParam& param, bool& is_continue);
    bool IsRunning();
    bool OnLogout(const std::string& msgid, MsgBusParam& param, bool& is_continue);
    bool OnTextMsg(const std::string& msgid, MsgBusParam& param, bool& is_continue);
    bool OnIMMainError(const std::string& msgid, MsgBusParam& param, bool& is_continue);
    bool OnIMContactsReady(const std::string& msgid, MsgBusParam& param, bool& is_continue);
    bool OnIMAddContact(const std::string& msgid, MsgBusParam& param, bool& is_continue);
    bool OnIMSubscriptionMsg(const std::string& msgid, MsgBusParam& param, bool& is_continue);
    bool OnIMVerifyUserUpdate(const std::string& msgid, MsgBusParam& param, bool& is_continue);
    bool OnIMNeedAuthCode(const std::string& msgid, MsgBusParam& param, bool& is_continue);
    bool OnIMLoginFailed(const std::string& msgid, MsgBusParam& param, bool& is_continue);
    bool OnIMLoginOK(const std::string& msgid, MsgBusParam& param, bool& is_continue);
    bool OnIMRspExportBinMsgs(const std::string& msgid, MsgBusParam& param, bool& is_continue);
    bool OnIMFileTransferNotify(const std::string& msgid, MsgBusParam& param, bool& is_continue);
    bool OnIMPicTransferFinished(const std::string& msgid, MsgBusParam& param, bool& is_continue);

    bool OnDoLogin(const std::string& msgid, MsgBusParam& param, bool& is_continue);
    bool OnDoReLogin(const std::string& msgid, MsgBusParam& param, bool& is_continue);
    bool OnDoLogout(const std::string& msgid, MsgBusParam& param, bool& is_continue);
    bool OnDoVerifyUser(const std::string& msgid, MsgBusParam& param, bool& is_continue);
    bool OnDoSendTextMessage(const std::string& msgid, MsgBusParam& param, bool& is_continue);
    bool OnDoPrintContacts(const std::string& msgid, MsgBusParam& param, bool& is_continue);
    bool OnDoQuit(const std::string& msgid, MsgBusParam& param, bool& is_continue);
    bool OnDoSendFile(const std::string& msgid, MsgBusParam& param, bool& is_continue);
    bool OnDoExportBinMsgs(const std::string& msgid, MsgBusParam& param, bool& is_continue);
    bool OnDoNotifyOtherSide(const std::string& msgid, MsgBusParam& param, bool& is_continue);
    void HealthCheckThreadFunc();

private:
    std::string m_wwmain_unique;
    bool  m_running;
    std::map<std::string, wwbiz::ContactContainerT> m_all_group2contacts;
    wwbiz::ContactContainerT  m_all_contacts;
    std::set<std::string>   m_all_tagnames;
    int m_healthtimerid;
    bool m_is_inloginsession;
    std::string m_exportfilepath;
    std::map<std::string, FileTransferNotify>  m_all_transfersession;
};

#endif
